﻿/**
 * 字体花屏问题
 * UGUI的动态字体会动态生成材质,当材质放不下这么多字的时候,会重建字体材质
 * 监听重建字体材质的方法,刷新文字显示
**/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextRebuilt : MonoBehaviour
{
    private Font needRebuildFont;
    void Start()
    {
        Font.textureRebuilt += OnTextureRebuilt;
    }

    private void OnTextureRebuilt(Font obj)
    {
        needRebuildFont = obj;
    }

    void Update()
    {
        if (needRebuildFont)
        {
            Text[] texts = GameObject.FindObjectsOfType<Text>();
            if (texts != null)
            {
                for (int i = 0; i < texts.Length; i++)
                {
                    if (texts[i].font == needRebuildFont)
                    {
                        texts[i].FontTextureChanged();
                    }
                }
            }
        }
    }
}
